package com.tulei.admin.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.tulei.common.response.R;
import com.tulei.system.Entity.SysMenu;
import com.tulei.system.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单操作
 **/

@RequiredArgsConstructor
@RestController
@Api(value = "菜单管理", tags = {"菜单管理"})
@RequestMapping(value = "/menu", method = {RequestMethod.POST, RequestMethod.GET})
public class MenuController {

    private final MenuService menuService;

    @PostMapping("/list")
    public R<List<SysMenu>> list() {
        List<SysMenu> menus = menuService.selectMenuList(Long.valueOf(StpUtil.getLoginId().toString()));
        return R.ok(menus);
    }

    @ResponseBody
    @ApiOperation("根据权限获取菜单列表的ID")
    @RequestMapping("/getList/ByRole/{access}")
    public R<List<Integer>> getMenuListByRole(@PathVariable("access") Integer access) {
        return R.ok(menuService.getMenuListByRole(access));
    }




}
